home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / HMSToTicks.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  1.6 KB  |  77 lines  |  [TEXT/MPS ]

  1. (*
  2.     HMSToTicks() -- Convert from HMS format to 1/60ths of a second
  3.  
  4.     To compile and link this file using Macintosh Programmer's Workshop,
  5.  
  6.         pascal -w HMSToTicks.p
  7.  
  8.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=8000 -sn Main=HMSToTicks ∂
  9.             HMSToTicks.p.o "{MPW}"PLibraries:PasLib.o
  10.  
  11.     Copyright © 1988 Apple Computer, Inc.
  12.  
  13.     2/88 - Initial coding by Harry R. Chesley.
  14. *)
  15.  
  16. {$R-}
  17.  
  18. {$S HMSToTicks }     { Segment name must be the same as the command name. }
  19.  
  20. unit DummyUnit;
  21.  
  22. interface
  23.  
  24. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  25.  
  26. procedure EntryPoint(paramPtr: XCmdPtr);
  27.     
  28. implementation
  29.  
  30. type
  31.  
  32. Str31 = String[31];
  33.  
  34. procedure HMSToTicks(paramPtr: XCmdPtr); forward;
  35.  
  36. procedure EntryPoint(paramPtr: XCmdPtr);
  37.  
  38.     begin
  39.         HMSToTicks(paramPtr);
  40.     end;
  41.  
  42. procedure HMSToTicks(paramPtr: XCmdPtr);
  43.  
  44.     var str: Str255;
  45.         i: integer;
  46.  
  47.     {$I XCmdGlue.inc}
  48.  
  49.     procedure Fail(errMsg: Str255); { set theResult and quit }
  50.         begin
  51.             paramPtr^.returnValue := PasToZero(errMsg);
  52.             exit(HMSToTicks);
  53.         end;
  54.  
  55.     {$I VideoUtil.inc}
  56.  
  57.     function pairAt(index: integer): longInt;
  58.         { Return a number which corresponds to the two digit value at str[index] and str[index+1]. }
  59.  
  60.         begin
  61.             pairAt := 10*(ord4(str[index])-ord4('0'))+(ord4(str[index+1])-ord4('0'));
  62.         end;
  63.  
  64.     begin
  65.         if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
  66.  
  67.         { Get the HMS form, and make sure it's the right length. }
  68.         GetStrParm(1,str);
  69.         if length(str) > 6 then str := Copy(str,length(str)-5,6);
  70.         for i := length(str) to 5 do str := Concat('0',str);
  71.  
  72.         { Calculate the ticks form. }
  73.         paramPtr^.returnValue := PasToZero(LongToStr(60*(pairAt(5)+60*(pairAt(3)+60*pairAt(1)))));
  74.     end;
  75.  
  76. end.
  77.